package com.xiaohe66.web.infrastructure.mybatis.sys.sec.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.sys.sec.agg.SecEncrypt;
import com.xiaohe66.web.domain.sys.sec.repository.SecEncryptRepository;
import com.xiaohe66.web.domain.sys.sec.value.SecEncryptId;
import com.xiaohe66.web.infrastructure.mybatis.sys.sec.convert.SecEncryptDoConverter;
import com.xiaohe66.web.infrastructure.mybatis.sys.sec.mapper.SecEncryptMapper;
import com.xiaohe66.web.infrastructure.mybatis.sys.sec.model.SecEncryptDo;
import com.xiaohe66.web.integration.AbstractMybatisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * @author xiaohe
 * @since 2024-01-03 11:30
 */
@Repository
@Slf4j
@RequiredArgsConstructor
public class SecEncryptRepositoryImpl
        extends AbstractMybatisService<SecEncryptDoConverter, SecEncryptMapper, SecEncryptDo, SecEncrypt, SecEncryptId>
        implements SecEncryptRepository {

    @Override
    public SecEncrypt getByCreateId(AccountId createId) {

        LambdaQueryWrapper<SecEncryptDo> queryWrapper = new LambdaQueryWrapper<SecEncryptDo>()
                .eq(SecEncryptDo::getCreateId, createId.getValue());

        SecEncryptDo entity = getOne(queryWrapper);

        SecEncrypt agg = dataConverter.toAgg(entity);

        saveSnapshot(agg);

        return agg;
    }
}
